package com.evaluationsystem.system.controller;

import com.evaluationsystem.system.entity.UserInfo;
import com.evaluationsystem.system.serivce.UserInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("userInput")
@Api("用户录入 CRUD 接口")
public class UserInputController {

    @Autowired
    UserInfoService service;

    @GetMapping("")
    @ApiOperation(value = "用户录入页面跳转接口")
    public String getUserInputHtml(){
        return "system/userInput/UserInput";
    }

    @GetMapping("changePwd")
    @ApiOperation(value = "修改密码页面跳转接口")
    public String getChangePwdHtml(){
        return "public/page/user/changePwd";
    }

    @GetMapping("userInfo")
    @ApiOperation(value = "个人信息页面跳转接口")
    public String getUserInfoHtml(){
        return "public/page/user/userInfo";
    }

    @PostMapping("addUser")
    @ResponseBody
    @ApiOperation(value = "新增用户",notes = "userid:必填项，长度8，username：必填项，长度50，password：必填项，长度80")
    @ApiImplicitParams({
            @ApiImplicitParam(name="userid",value = "用户账号",required = true,paramType = "form"),
            @ApiImplicitParam(name="username",value = "用户名称",required = true,paramType = "form"),
            @ApiImplicitParam(name="password",value = "密码",required = true,paramType = "form")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "保存成功"),
            @ApiResponse(code = 5001, message = "账号已存在"),
            @ApiResponse(code = 5002, message = "接口异常，请联系管理员"),
    })
    public Map<String,Object> addUser(@RequestBody UserInfo userInfo){
        Map<String,Object> res = service.insert(userInfo);
        return res;
    }

    @PostMapping("getTableList")
    @ResponseBody
    @ApiOperation(value = "用户列表查询",notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name="userid",value = "用户账号",required = true,paramType = "form"),
            @ApiImplicitParam(name="username",value = "用户名称",required = true,paramType = "form"),
            @ApiImplicitParam(name="password",value = "密码",required = true,paramType = "form")
    })
    public Map<String,Object> getTableList(@RequestBody Map<String,Object> param){
        Map<String,Object> res = service.getTableList(param);
        return res;
    }

    @PostMapping("uptypeById")
    @ResponseBody
    @ApiOperation(value = "用户 禁用/启用 修改 接口",notes = "2020-4-14，gdy")
    public Map<String,Object> uptypeById(@RequestBody Map<String,Object> param){
        Map<String,Object> res = service.uptypeById(param);
        return res;
    }

    @GetMapping("getUpdata/{userid}")
    @ApiOperation(value = "用户 修改页面 跳转 接口",notes = "2020-4-14，gdy")
    public String getUpdata(@PathVariable("userid") String userid, Map<Object,Object> map){
        map.put("userid",userid);
        return "system/userInput/UserInputUpdata";
    }

    @PostMapping("selectByUserId")
    @ResponseBody
    @ApiOperation(value = "用户 修改页面 用户信息加载 接口",notes = "2020-4-14，gdy")
    public Map<String,Object> selectByUserId(@RequestBody Map<String,Object> param){
        Map<String,Object> res = service.selectByUserId(param);
        return res;
    }


    @PostMapping("updateUserByid")
    @ResponseBody
    @ApiOperation(value = "用户 修改页面 保存 接口",notes = "2020-4-14，gdy")
    public Map<String,Object> updateUserByid(@RequestBody Map<String,Object> param){
        Map<String,Object> res = service.updateUserByid(param);
        return res;
    }




}
